﻿/*
 * @Autor: PK
 * @Date: 2021/12/25 16:09:SS
 */

using System.Collections.Generic;
using ShkSimulation.core.dao.statistic.impl;
using ShkSimulation.core.exceptions;

namespace ShkSimulation.core.dao.statistic {

	public class ListenerGenerator {
		
		public static Dictionary<DataReporterCollection, ResultListener> CreateListenersByReporters(Dictionary<string, DataReporterCollection> reportersDictionary) {
			Dictionary<DataReporterCollection, ResultListener> result = new Dictionary<DataReporterCollection, ResultListener>();
			foreach (var (key, dataReporter) in reportersDictionary) {
				if (result.ContainsKey(dataReporter)) {
					throw new ErrorParamException($"不允许同一个Key有多个DataReporter: {key}");
				}
				ResultListener listener = new DefaultResultCollectionListener(key, CollectionReportData.ExportCollectionAction);
				result.Add(dataReporter, listener);
			}
			return result;
		}
		
		public static ResultListener CreateListenerByReporter(DataReporterCollection reporter) {
			return new DefaultResultCollectionListener(reporter.Uniquekey, CollectionReportData.ExportCollectionAction);
		}

	}
}